package com.zhy.springmvc.service.impl;

import com.zhy.springmvc.dao.AdminDao;
import com.zhy.springmvc.entity.Admin;
import com.zhy.springmvc.service.intf.AdminService;
import com.zhy.springmvc.util.Rutil;
import com.zhy.springmvc.vo.PageBean;
import com.zhy.springmvc.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminServiceImpl  implements AdminService {
    @Autowired
    private AdminDao dao;
    @Override
    public R save(Admin admin) {
        if (admin != null && admin.getName()!= null){
            admin.setPassword(DigestUtils.md5DigestAsHex(admin.getPassword().getBytes()));
            if (dao.insert(admin) > 0){
                return Rutil.ok();
            }
        }
        return Rutil.fail();
    }

    @Override
    public PageBean qusertList() {
        List<Admin> list = dao.selectAll();
        return new PageBean(0,"",list.size(),list);
    }
}
